package com.pc.service;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.additional.query.impl.QueryChainWrapper;
import com.pc.entity.Userlog;
import com.pc.mapper.UserlogMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * ClassName: UserlogService <br/>
 * Description: <br/>
 * date: 2023/1/16 10:50<br/>
 *
 * @author 李林雨 <br/>
 * @since JDK 8
 */
@Service
public class UserlogService {
    @Resource
    private UserlogMapper userlogMapper;

    //向表中插入
    public boolean addUserLog(Userlog userlog){
        int insert = userlogMapper.insert(userlog);
        return insert!=0;
    }

    //导出表中所有日志
    public List<Userlog> getAllUserLog(){
        QueryWrapper<Userlog> wrapper = new QueryWrapper<>();
        return userlogMapper.selectList(wrapper);
    }

    //根据用户账号进行排序
    public List<Userlog> getUserLogByUsername(String username){
        QueryWrapper<Userlog> wrapper = new QueryWrapper<>();
        wrapper.eq("username",username);
        return userlogMapper.selectList(wrapper);
    }

    //日志分页查询
    public List<Userlog> getUserLogPage(int nowpage){
        return userlogMapper.getList(nowpage*10,10);
    }
}
